/**
 * 模板管理页面JS
 * User: zhaoming
 * Date: 201616-07-05
 * Time: 下午5:58
 * To change this template use File | Settings | File Templates.
 */
$(function(){

    //激活左侧导航
    activeNavBar("template", "basic");

    //加载数据列表
    loadGrid();

    //重置数据列表宽度
    $("#gridTableWidgetBody").resize(function(){
        $("#gridTable").setGridWidth($(this).width(), false);
    });
});

/**
 * 加载数据列表
 */
function loadGrid(){
    var gridTable = jQuery("#gridTable");
    gridTable.jqGrid({
        mtype:"POST",
        url: "/web/template/selectAll.json",
        datatype: "json",
        autowidth: true,
        height: "450",
        colModel:[
            {name:'code',label:'模板编码', index:'code', width:100, fixed:false, sortable: false, align:'center'},
            {name:'name',label:'模板描述', index:'name', width:100, fixed:false, sortable: false, align:'center'},
            {name:'templateName',label:'模板名称', index:'templateName', width:100, fixed:false, sortable: false, align:'center'},
            {name:'filePath',label:'生成文件的存放路径', index:'filePath', width:100, fixed:false, sortable: false, align:'center'},
            {name:'fileName',label:'生成文件的后缀名', index:'fileName', width:100, fixed:false, sortable: false, align:'center'},
            {name:'', label:'操作', width:150, fixed:true, sortable:false, align:'center', frozen:true,
                formatter:function(cellValue,options,rowObject){
                    var context = "";
                    context += '<button class="btn btn-white btn-info btn-bold" onclick="show('+options.rowId+')"><i class="ace-icon fa fa-eye bigger-120 blue"></i>查看模板</button> ';
                    return context;
                }
            }
        ],
        rownumbers:true,//添加左侧行号
        viewrecords : true,
        rowNum:1000,
        altRows: true,
        pager : "#gridPager",
        jsonReader: {
            root: "root", //对于json中数据列表
        },
        loadComplete : function() {
            updatePagerIcons(this);
            $(this).setGridWidth($("#gridTableWidgetBody").width(), true);
        }
    });
}

/**
 * 详情展示
 * @param selectedId 行号
 */
function show(selectedId){
    var rowData = $("#gridTable").jqGrid("getRowData", selectedId);
    window.location.href = "/web/template/show?templateName="+rowData.templateName+"&fileName="+rowData.fileName;
}
